Instantiating Applets
After you have created a session, located the applet, and created an AWT context for the applet, you can instantiate it. An instantiated applet is defined by anJMAppletViewerRef
object, and you use theJMNewAppletViewer
function (page 77) to create one. Listing 1-10 shows an example of instantiating an applet.Listing 1-10 Instantiating an applet
JMAppletViewerCallbacks viewerCallbacks = { kJMVersion, /* should be kJMVersion */ MyShowDocument, /* showDocument callback */ MySetStatusMsg /* setMessage callback */ }; JMAppletViewerRef viewer; err = JMNewAppletViewer(&viewer, context, locatorRef, appletIndex, &viewerCallbacks, 0); /* reload the applet to get it going */ if (err == noErr) { err = JMReloadApplet(viewer);You must define two callbacks,MyShowDocument
(page 107) andMySetStatusMsg
(page 107), when calling theJMNewAppletViewer
function. TheMyShowDocument
function displays the contents of a URL passed back from the applet, andMySetStatusMsg
displays any status messages the applet may pass to the application. You must also specify the index of the applet you want to instantiate (as returned byJMCountApplets
).After you have instantiated the applet viewer object, you must load and execute the applet code by calling the function
JMReloadApplet
(page 79).You can set or retrieve client data associated with the applet by using the functions
JMSetAppletViewerData
(page 79) andJMGetAppletViewerData
(page 78).At any time you can stop execution of the applet by calling the
JMSuspendApplet
function (page 80) and resume it by calling theJMResumeApplet
function (page 81). If you want to restart the applet without reloading it from the server, use theJMRestartApplet
function (page 80).When you are finished with an applet, you can dispose of it by calling the
JMDisposeAppletViewer
function (page 78). This function automatically halts applet execution and removes any frames associated with the applet.